package com.widget;

import com.devsmart.android.ui.HorizontalListView;
import com.swtplayer.R;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class CustomGallery extends RelativeLayout {

	private Context _context;
	public TextView tv;

	private int FontSize;

	public ImageView img;
	public RelativeLayout titlebox;
	public HorizontalListView mGallery;
 

	public void SetTitle(CharSequence str) {
		tv.setText(str);
	}

	public void SetMoreImg(Drawable drawableimg, Intent intent) {
		img.setImageDrawable(drawableimg);
		final Intent temp=intent;
		img.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				_context.startActivity(temp);
			}
		});
		
	}
 
	public void SetGalleryAdapter(ListAdapter adapter)
	{
		mGallery.setAdapter(adapter);	
		mGallery.invalidate();		 
	}
	
	

	 
	
 	public CustomGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
		_context = context;
		// TODO Auto-generated constructor stub
		int resouceId = -1;
		TypedArray typeArray = context.obtainStyledAttributes(attrs,
				R.styleable.CustomGallery);

		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li = (LayoutInflater) context
				.getSystemService(infService);

		View view = LayoutInflater.from(context).inflate(
				R.layout.customgallery, this, true);

		tv = (TextView) view.findViewById(R.id.type_title);
		mGallery = (HorizontalListView) view.findViewById(R.id.movie_gallery);
		 
		img = (ImageView) view.findViewById(R.id.moreicon);
		titlebox = (RelativeLayout) view.findViewById(R.id.type_title_box);
		int N = typeArray.getIndexCount();
		for (int i = 0; i < N; i++) {
			int attr = typeArray.getIndex(i);
			switch (attr) {
			case R.styleable.CustomGallery_Morepic:			 
				img.setImageDrawable(typeArray.getDrawable(R.styleable.CustomGallery_Morepic));
				break;
				
			case R.styleable.CustomGallery_GallerySpaceing:
				int space = (int)typeArray.getFloat(R.styleable.CustomGallery_GallerySpaceing, 5) ;
				 
				break;
				
			case R.styleable.CustomGallery_Oriental:
				resouceId = typeArray.getResourceId(
						R.styleable.CustomGallery_Oriental, 0);
				 
				break;

			case R.styleable.CustomGallery_FontSize:
				resouceId = typeArray.getResourceId(
						R.styleable.CustomGallery_FontSize, 0);
				tv.setTextSize(typeArray.getFloat(
						R.styleable.CustomGallery_FontSize, 12));
				break;

			case R.styleable.CustomGallery_TitleText:
				resouceId = typeArray.getResourceId(
						R.styleable.CustomGallery_TitleText, 0);
				tv.setText(resouceId > 0 ? typeArray.getResources().getText(
						resouceId) : typeArray
						.getString(R.styleable.CustomGallery_TitleText));
				break;

			}
		}

	}

}
